<template>
  <div class="login-box">
    <!--<label style="color: #646566">用户登录</label>-->
    <van-form @submit="loginSubmit" :model="form">
      <van-field
        v-model="form.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: false}]"
      />
      <van-field
        v-model="form.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: false}]"
      />
      <div style="margin: 16px;">
        <van-button block type="info" style="border-radius: 5px" native-type="submit">
          提交
        </van-button>
      </div>
      <div>
        <router-view/>
      </div>
    </van-form>
  </div>
</template>

<script>
  export default {
    name: 'login',
    data() {
        return {
          form: {
            username: '',
            password: ''
          }
        }
    },
    methods: {
      loginSubmit(){
        if (!this.form.username){
          this.$toast("请输入用户名");
          return
        }
        if (!this.form.password){
          this.$toast("请输入密码");
          return
        }
        //登陆提交
        /*this.$http({
          method: 'post',
          url: 'index/login/login',
          data: {
            username: this.form.username,
            password: this.form.password
          }
        }).then(res => {
          this.$toast.success('登陆成功')
        })*/
        this.$toast.success('登陆成功')
        debugger
        const url = this.$route.query.redirect || "/user";
        this.$router.push({path: url});
      }
    }
  };
</script>
<style>
  .login-box {
    margin-top: 5rem;
  }
</style>
